package cron.core.scheduler.trigger;

import cron.core.scheduler.timer.TimeWheel;
import cron.task.plugin.Task;

import java.util.Date;

/**
 * @author : willian fu
 * @version : 1.0
 * @date : 2021/3/9 0009 17:34
 */
public abstract class AbstractTrigger implements Trigger{

    protected Date nextTime;

    protected Task worker;

    protected long count;

    protected TimeWheel timeWheel;

    protected boolean enable = false;

    protected final static int UNIT = 1000;

    @Override
    public void setCount(long count) {
        this.count = count;
    }

    @Override
    public void setTimeWheel(TimeWheel timeWheel) {
        this.timeWheel = timeWheel;
    }

    @Override
    public void toNext() {
        timeWheel.removeTrigger(this);
        timeWheel.addTrigger(this);
    }

    @Override
    public boolean isEnable() {
        return this.enable;
    }

    @Override
    public void enable() {
        this.enable = true;
    }

    @Override
    public void disable() {
        this.enable = false;
    }

    @Override
    public void run() {
        toNext();
    }
}
